<style lang="scss" scoped>
  .bodyBox >.title {
    margin: 15px 0;
    font-weight: bold;
    color: #333;
  }
  .formBox {
    margin-top: 15px;
  }
  .formBox .title {
    margin: 15px 0;
    font-weight: bold;
    color: #333;
  }
  .formItem {
    width: 95%;
  }
  .describe {
    color: #999;
    margin-left: 10px;
  }
  .imgBox {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 80px;
    width: 80px;
    .avatar {
      height: 100%;
      width: 100%;
    }
  }

	.imgBoxWarpGrid > div {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		.imgBoxWarpGrid-imgBox {
			position: relative;
			flex-direction: column;
			padding-top: 10px;
			max-height: 130px;
			width: 120px;
			margin: 10px 15px;
			border: 1px solid #f8f8f8;
			cursor: pointer;
			.deleteIcons {
				position: absolute;
				top: -18px;
    			right: -5px;
			}
			.avatar {
				height: 80px;
				width: 80px;
				border-radius: 10px;
			}
			.resource_auth {
				font-size: 14px;
				width: 100%;
				text-align: center;
			}
			audio {
				width: 120px;
				height: 40px;
			}
		}
  }
  
</style>
<template>
    <div class="bodyBox">
      <el-form ref="form" :model="formData" :rules="rules" class="formBox" label-width="80px" v-loading="showLoading">
        <p class="title">作品基本信息</p>
        <div class="flex-between" style="align-items: flex-start;">
            <div class="flex_1">
				<el-form-item label="作品类型"  verify prop="resourceType">
					<el-select
						class="formItem"
						v-model="formData.resourceType"
						placeholder="作品类型"
						disabled
						@change="checkCardType">
						<el-option
							v-for="item in resourceTypes"
							:key="item.resourceType"
							:label="item.name"
							:value="item.resourceType"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="绑定活动" verify prop="campaignUid" v-if="formData.resourceType === 6">
					<el-select
						class="formItem"
						v-model="formData.campaignUid"
						prop="campaignUid"
						placeholder="绑定活动"
						@change="handleBind">
						<el-option
							v-for="item in campaignList"
							:key="item.campaignUid"
							:label="item.campaignSubject"
							:value="item.campaignUid"></el-option>
							<div class="text-center" style="position: sticky;background: #fff;height:30px;top:0;z-index:1">
							<a class="text-normal">
								<el-pagination
									@current-change="checkCampaignListPage"
									:current-page="campaignListPage"
									:page-size="10"
									background
									layout="total, prev, pager, next, jumper"
									:total="campaignListCount" />
							</a>
						</div>
					</el-select>
				</el-form-item>
            <el-form-item label="作品类别" verify prop="resourceKind">
              <el-select
                class="formItem"
                v-model="formData.resourceKind"
                placeholder="作品类别"
                @change="checkKind"
              >
                <el-option
                  v-for="item in resourceKinds"
                  :key="item.resourceKind"
                  :label="item.name"
                  :value="item.resourceKind"
                ></el-option>
              </el-select>
              </el-form-item>
               <el-form-item :label="formData.resourceType === 6 ? '活动名' : '作品名'" prop="resourceName" verify>
                <el-input
                  class="formItem"
                  v-model="formData.resourceName"
				  :disabled="formData.resourceType === 6 &&　!!formData.resourceName"
                  maxlength="20"
                  placeholder="请输入作品名，20字内 (长度不超过20)"
                ></el-input>
              </el-form-item>
              <el-form-item :label="formData.resourceType === 6 ? '活动描述' : '作品描述'" prop="resourceDesc" verify>
              <el-input
                class="formItem"
                type="textarea"
                :rows="4"
				:disabled="formData.resourceType === 6 &&　!!formData.resourceDesc"
                v-model="formData.resourceDesc"
                maxlength="100"
                placeholder="请输入作品描述 (长度不超过100)"
              ></el-input>
            </el-form-item>
            <!-- <el-form-item label="选择标签" verify prop="resourceLabelTreeCodes">
              <div class="header">选择标签</div>
              <el-tree
                ref="tree"
                show-checkbox
                :data="labelList"
                node-key="labelTreeCode"
                :props="defaultProps"
                :default-checked-keys="this.curLabels"
                :default-expanded-keys="this.curLabels"
                @check-change="checkLabels"
                :accordion="true"
              >
              </el-tree>
              <div style="margin-top: 20px">
                <el-button type="primary" @click="checkAllTree" size="mini">全选</el-button>
                <el-button @click="cancelAllTree" size="mini">取消全选</el-button>
              </div>
            </el-form-item>-->
            <el-form-item label="祝福语" prop="resourceDefaultBlessingText" verify v-if="formData.resourceType !== 6">
              <el-input
                class="formItem"
                type="textarea"
                :rows="2"
                v-model="formData.resourceDefaultBlessingText"
                maxlength="100"
                placeholder="请输入默认祝福语 (长度不超过100)"
              ></el-input>
            </el-form-item>

           <!-- <el-form-item label="设置标记" verify prop="resourceMarkType">
              <el-select
                class="formItem"
                v-model="formData.resourceMarkType"
                placeholder="请选择标记内容"
                @change="checkMarker"
              >
                <el-option
                  v-for="item in markerList"
                  :key="item.markerId"
                  :label="item.markerName"
                  :value="item.markerId"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item label="选择作者"  prop="resourceAuthorUid" verify>
              <el-select
                class="formItem"
                v-model="formData.resourceAuthorUid"
                placeholder="请选择作者"
                @change="checkAuthor"
              >
                <el-option
                  v-for="item in authorList"
                  :key="item.memberUid"
                  :label="deCodes(item.wechatNickName)"
                  :value="item.memberUid"
                ></el-option>
              </el-select>
            </el-form-item>
			<el-form-item label="绑定商品" prop="bindProducts" v-if="formData.resourceType === 5">
              <el-select
                class="formItem"
                v-model="bindProducts"
                placeholder="请选择商品"
                @change="checkGoods"
                filterable
				multiple
				collapse-tags>
                <el-option
                  	v-for="item in goodsList"
					:key="item.productUid"
					:label="item.productName"
					:value="item.productUid">
				</el-option>
				<el-pagination
					@current-change="checkGoodsPage"
					:current-page="goodsListPage"
					:page-size="10"
					hide-on-single-page
					background
					layout="total, prev, pager, next, jumper"
					:total="goodsListCount">
				</el-pagination>
              </el-select>
            </el-form-item>
            <el-form-item label="绑定音乐"  prop="resourceMusicUid" verify>
              <el-select
                class="formItem"
                v-model="formData.resourceMusicUid"
                placeholder="请选择音乐 (可选)"
                @change="checkMusic"
                filterable
              >
                <el-option
                  v-for="item in musicList"
                  :key="item.musicId"
                  :label="item.musicName+'--歌手：'+item.musicSinger"
                  :value="item.musicId"
                ></el-option>
				<div class="text-center" style="position: sticky;background: #fff;height:30px;top:0;z-index:1">
					<a class="text-normal">
						<el-pagination
							@current-change="checkMusicPage"
							:current-page="musicListPage"
							:page-size="10"
							background
							layout="total, prev, pager, next, jumper"
							:total="musicListCount"/>
					</a>
				</div>
              </el-select>
            </el-form-item>
			<el-form-item label="排序"  prop="resourceSort" verify>
				<el-input
					class="formItem"
					type="number"
					min="1"
					v-model="formData.resourceSort"
					placeholder="请输入排序 (值越大越靠前)"
				></el-input>
			</el-form-item>
            <el-form-item  label="定时发布"  prop="timingRelease">
              <el-date-picker
                class="formItem"
                v-model="formData.timingRelease"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间 (可选)">
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="flex_1">
            <el-form-item verify label="封面图" prop="resourceCoverImageUrlUid">
              <p class="describe">提示：本地上传图片大小不能超过1M【图片尺寸比例建议：贺卡(9：16)；插画：(16：9)；条漫：(1：1)】</p>
              <el-upload
                :action="uploadUrl"
                :data="access_token"
                :show-file-list="false"
                :on-change="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
                :on-success="uploadSuccessCover"
                :class="formData.resourceType !== 5 ? '' : 'upload-card-box'"
              >
                <div class="imgBox" v-if="resourceCoverImageUrl && formData.resourceType === 5">
                  <img :src="resourceCoverImageUrl" class="avatar" />
                </div>
                <img :src="resourceCoverImageUrl" class="avatar" v-else-if="resourceCoverImageUrl && formData.resourceType !== 5" />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                <el-input class="inputs none imgArea" v-model="formData.resourceCoverImageUrlUid"></el-input>
              </el-upload>
            </el-form-item>

            <el-form-item verify label="资源文件" prop="resourceFileUid">
				<!--上传图片文件-->
				<div v-if="formData.resourceType !== 4">
					<p class="describe">提示：本地上传图片大小不能超过1M</p>
					<el-upload
						:action="uploadUrl"
						:data="access_token"
						:show-file-list="false"
						:on-change="handleAvatarSuccess"
						:before-upload="beforeAvatarUpload"
						:on-success="uploadSuccess"
						:class="formData.resourceType !== 5 ? '' : 'upload-card-box'"
                		:list-type="formData.resourceType !== 5 ? 'picture' : 'picture-card'"
					>
						<div class="imgBox" v-if="resourceImageUrl && formData.resourceType === 5">
							<el-image :src="resourceImageUrl" class="avatar" />
						</div>
						<el-image :src="resourceImageUrl" class="avatar" v-else-if="resourceImageUrl && formData.resourceType !== 5" />
						<i v-else class="el-icon-plus avatar-uploader-icon"></i>
						<el-input class="inputs none imgArea" v-model="formData.resourceFileUid"></el-input>
					</el-upload>
				</div>
				<!--上传非图片文件-->
				<div v-if="formData.resourceType === 4">
					<el-upload
						:action="$uploadUrl"
						:data="QiniuData"
						:before-upload="beforeAvatarUploadVideo"
						:on-preview="handlePreview"
						:on-remove="handleRemove"
						:before-remove="beforeRemove"
						:on-success="uploadSuccessVideo"
						:on-exceed="handleExceed"
						:on-error="uploadError"
						:file-list="fileList">
						<video :src="resourceUrl" class="avatar" v-if="resourceUrl" />
						<el-button size="small" type="primary" v-else>点击上传</el-button>
						<el-input class="inputs none imgArea" v-model="formData.resourceFileUid"></el-input>
					</el-upload>
				</div>
            </el-form-item>
            <el-form-item label="合集文件" v-if="formData.resourceType === 5">
				<div>
					<div class="imgBoxWarpGrid">
						<div class="selectBox" v-if="dragTags.length < 9">
							<el-upload
								:action="uploadUrl"
								:data="access_token"
								:file-list="fileList"
								:before-upload="beforeUplaodFile"
								:on-success="uploadILLUSTRATIONSuccess"
								:limit="9"
								style="margin-left:20px"
								:show-file-list="false"
							>
								<el-button size="small" type="primary">上传贺卡</el-button>
							</el-upload>
							<el-upload
								:action="uploadUrl"
								:data="access_token"
								:file-list="fileList"
								:before-upload="beforeUplaodFile"
								:on-success="uploadCARTOONSuccess"
								:limit="9"
								:show-file-list="false"
								style="margin-left:20px"
							>
								<el-button size="small" type="primary">上传漫画</el-button>
							</el-upload>
							<el-upload
								:action="$uploadUrl"
								:data="QiniuData"
								:file-list="fileList"
								:before-upload="beforeUplaodFile"
								:on-success="uploadFileSuccess"
								:limit="9"
								:on-error="uploadError"
								:show-file-list="false"
								style="margin-left:20px"
							>
								<el-button size="small" type="primary">上传视频</el-button>
							</el-upload>
						</div>
						<draggable v-model="dragTags" :move="getdata" @update="datadragEnd" :options="{animation:500}">
							<div class="imgBoxWarpGrid-imgBox flex-center" v-for="item in dragTags" :key="item.resourceFileUrlUid">
								<img :src="item.resourceFileUrl" class="avatar" v-if="item.resourceType !== 4" />
								<video :src="item.resourceFileUrl" class="avatar" v-if="item.resourceType === 4" />
								<div class="resource_auth" @click="handleSelect(item)">
									{{item.resourceAuthorUid ? '作者：' + filterAuthName(item.resourceAuthorUid) : '请选择作者'}}
								</div>
								<div class="deleteIcons" @click="handleDel(item)">
									<i class="el-icon-circle-close"></i>
								</div>
							</div>
						</draggable>
					</div>
				</div>
            </el-form-item>
          </div>
        </div>
		<!--   发布按钮     -->
        <div class="footer flex-center">
          	<el-button type="primary" @click="updateSubmit">确认</el-button>
          	<el-button @click="closeDialog(false)">取  消</el-button>
			<!-- <el-button type="primary" @click="previewData()">预览</el-button> -->
        </div>
      </el-form>
      <!-- 内嵌弹出层 -->

	  	<el-dialog
			width="30%"
			title="选择作者"
			:visible.sync="innerVisible"
			append-to-body>
			<el-form ref="form" :model="selectAuthData" class="formBox" label-width="80px" v-loading="showLoading">
			<el-form-item>
				<el-select
				class="formItem"
				v-model="selectAuthData.resourceAuthorUid"
				placeholder="请选择作者"
				@change="innerPopAuthor"
				>
				<el-option
					v-for="item in authorList"
					:key="item.memberUid"
					:label="deCodes(item.wechatNickName)"
					:value="item.memberUid"
				></el-option>
				</el-select>
			</el-form-item>
			<!-- <div class="footer flex-center">
				<el-button type="primary" @click="addAuth">确认</el-button>
				<el-button  @click="cancelAuth">取 消</el-button>
			</div> -->
			</el-form>
		</el-dialog>
    </div>
</template>

<script>
    import {
        blessingUpdate,
        blessingAdd,
		labelListAll,
		getQiniuToken, // 获取token
        labelListByBusinessType
    } from "@/api/table";
    import draggable from 'vuedraggable';
    export default {
		name: "BLESSING_EDIT",
		components: {
			draggable
		},
		props: {
			transData: {
				type: Object,
				default: {}
			},
			authorList: {
				type: Array,
				default: []
			},
			campaignList: {
				type: Array,
				default: []
			},
			musicList: {
				type: Array,
				default: []
			},
			resourceTypes: {
				type: Array,
				default: []
			},
			musicListPage: {
				type: Number,
				default: 1
			},
			musicListCount: {
				type: Number,
				default: 0
			},
			campaignListPage: {
				type: Number,
				default: 1
			},
			campaignListCount: {
				type: Number,
				default: 0
			},
			goodsList: {
				type: Array,
				default: []
			},
			goodsListPage: {
				type: Number,
				default: 0
			},
			goodsListCount: {
				type: Number,
				default: 0
			},
		},
		watch: {
			transData(newVal, oldVal) {
				this.formData = newVal;
				this.resourceCoverImageUrl = newVal.resourceCoverImageUrl;
				this.resourceImageUrl = newVal.resourceFileUrl;
				this.resourceUrl = newVal.resourceFileUrl;
				if (newVal.resourceType === 5) {
					this.dragTags = newVal.resourceFiles;
					let bindProducts = []
					this.formData.productInfoModels &&　this.formData.productInfoModels.map(item => {
						return bindProducts.push(item.productUid)
					})
					this.bindProducts = bindProducts;
				}
				
				// console.log(this.formData, oldVal)
			}
		},
		data() {
			return {
				QiniuData: {
					key: "", //图片名字处理
					token: "" //七牛云token
				},
				formData: this.transData,
				labelList:[],
				fontList:[],
				markerList:[
					{
						markerId:1,
						markerName:"无标记",
					},
					{
						markerId:2,
						markerName:"最新",
					},
					{
						markerId:3,
						markerName:"人气",
					}
				],
				labels:[],
				uploadUrl: process.env[this.$base] + "/medias/image/upload",
				access_token: {
					access_token: this.$store.getters.token
				},
				uploadUrl:process.env[this.$base] + "/medias/image/upload",
				fileList:[],
				resourceCoverImageUrl: this.transData.resourceCoverImageUrl,
				resourceImageUrl: this.transData.resourceFileUrl,
				resourceUrl: this.transData.resourceFileUrl,
				dragTags: this.transData.resourceFiles || [],
				//预存选择的标签
				checkedLabels:[],
				//树形所需
				defaultProps: {
					children: "child",
					label: "labelText"
				},
				curLabels:[],
				//资源类别
				resourceKinds:[
					{
						resourceKind:1,
						name:"平台作者"
					},
					{
						resourceKind:2,
						name:"第三方创作者"
					}
				],
				rules: {
					resourceName: [{ required: true, message: "请输入作品名", trigger: "change" }],
					resourceType: [{ required: true, message: "请选择资源类型", trigger: "change" }],
				},
				showLoading: false,
				innerVisible: false,
				selectAuthData: {},
				//  组合里面的作者uid
				resourceAuthorUid: '',
				vueLoading: {},
				bindProducts: []
          	}
      	},
		created() {
			// 获取token
			this.getUploadToken();

			if (this.formData.resourceType === 5) {
				let bindProducts = []
				this.formData.productInfoModels &&　this.formData.productInfoModels.map(item => {
					return bindProducts.push(item.productUid)
				})
				this.bindProducts = bindProducts;
			}

			//labelList
			//遍历所有标签，进行标签树组装
			//初始化当前业务类型下的树
			labelListByBusinessType({labelBusinessType:"2"}).then(result => {
				if(result.data.isSuccessful === 'Y'){
					//将数据转为map，以labelTreeCode为标识
					let map = {};
					result.data.data.forEach( item => {
						map[item.labelTreeCode] = item
					});
					let labelArr = [];
					//然后遍历，只要当前item存在父标签parent则一直找，找到就设为其子标签
					result.data.data.forEach(item => {
						let parent = map[item.labelParentTreeCode];
						if(parent){
							(parent.child || (parent.child = [])).push(item)
						}else {
							//没有父标签，则就是一级标签
							labelArr.push(item)
						}
					});
					//重组标签树
					this.labelList = labelArr;
				}
			}).catch(err => {});
		},
     	 methods: {
			getUploadToken() {
				getQiniuToken().then(res => {
					if (res.code === 200) {
						this.QiniuData.token = res.data;
					}
				});
			},
			//上传图片
			handleAvatarSuccess(file, fileList) {},
			beforeAvatarUpload(file) {
				var type = "image/jpg,image/jpeg,image/png,image/gif";
				const isJPG = type.indexOf(file.type) != -1;
				const isLt1M = file.size / 1024 / 1024 < 1;

				!isJPG && this.$message.error("上传图片只能是 JPG,JPEG,PNG,GIF 格式!");
				!isLt1M &&　this.$message.error("上传图片大小不能超过 1MB!");

				return isJPG && isLt1M;
			},
			//封面图上传成功
			uploadSuccessCover(response, file, fileList) {
				if (response.code == "200") {
					this.formData.resourceCoverImageUrlUid = response.data.fileUid;
					this.resourceCoverImageUrl = response.data.fileUrl;
				}
			},
			//作品图上传成功
			uploadSuccess(response, file, fileList) {
				if (response.code == "200") {
					this.formData.resourceFileUid = response.data.fileUid;
					this.resourceImageUrl = response.data.fileUrl;
				}
			},
			//上传视频
			//上传文件的一些钩子
			handleRemove(file, fileList) {
				console.log(file, fileList);
			},
			handlePreview(file) {
				console.log(file);
			},
			handleExceed(files, fileList) {
				this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
			},
			beforeRemove(file, fileList) {
				// return this.$confirm(`确定移除 ${ file.name }？`);
			},
			//上传之前格式和大小判断
			beforeAvatarUploadVideo(file) {
				const isLt100M = file.size / 1024 / 1024 < 100;
				if(!isLt100M) {
					this.$message.error("视频文件大小不能超过 100MB!");
					return isLt100M
				}
				this.vueLoading = this.$loading({
					lock: true,
					text: '文件上传中，请稍后...',
					spinner: 'el-icon-loading',
					background: 'rgba(0, 0, 0, 0.7)'
				});
				this.QiniuData.key = file.uid;
				return isLt100M
			},

			uploadSuccessVideo(response, file, fileList) {
				if (response.hash) {
					this.resourceUrl = this.$qiniuAddr + file.uid,
					this.formData.resourceFileUid = response.hash,
					this.formData.videoInfo = JSON.stringify({
						resourceName: file.name,
						resourceSize: file.size,
						resourceType: file.raw.type,
						resourceUrl: this.$qiniuAddr + file.uid
					}),
					console.log(this.formData, 'formData')
				}
				this.vueLoading.close()
			},

			uploadError() {
				this.vueLoading.close()
			},

			// 上传任意文件
			beforeUplaodFile(file) {
				const imageType = "image/jpg,image/jpeg,image/png,image/gif";
				const isImage = imageType.indexOf(file.type) != -1;
				const isLt100M = file.size / 1024 / 1024 < 100;
				const isLt1M = file.size / 1024 / 1024 < 1;
				if(isImage && !isLt1M) {
					this.$message.error("上传图片大小不能超过 1MB!");
					return isLt1M
				}

				if(!isImage && !isLt100M) {
					this.$message.error("视频文件大小不能超过 100MB!");
					return isLt100M
				}

				if(!isImage && isLt100M) {
					this.vueLoading = this.$loading({
						lock: true,
						text: '文件上传中，请稍后...',
						spinner: 'el-icon-loading',
						background: 'rgba(0, 0, 0, 0.7)'
					});
				}
				this.QiniuData.key = file.uid;
				return true
			},

			// 任意文件上传成功回调
			uploadFileSuccess(response, file, fileList) {
				if (response.code == 200) {
					this.filterDragTargs(4, response);
					this.vueLoading.close()
				}
				if (response.hash) {
					this.dragTags.push({
						resourceFileUrl: this.$qiniuAddr + file.uid,
						resourceFileUrlUid: response.hash,
						resourceInfo: JSON.stringify({
							resourceName: file.name,
							resourceSize: file.size,
							resourceType: file.raw.type,
							resourceUrl: this.$qiniuAddr + file.uid
						}),
						resourceType: 4,
						resourceAuthorUid: this.formData.resourceAuthorUid
					});
					console.log(this.dragTags)
					this.vueLoading.close()
				}
			},
			
			uploadILLUSTRATIONSuccess(response, file, fileList) {
				if (response.code == 200) {
					this.filterDragTargs(1, response)
				}
			},
			uploadCARTOONSuccess(response, file, fileList) {
				if (response.code == 200) {
					this.filterDragTargs(3, response)
				}
			},

			// filterDragTargs
			filterDragTargs(resourceType, response) {
				const { fileUrl, fileUid } = response.data;
				this.dragTags.push({
					resourceFileUrl: fileUrl,
					resourceFileUrlUid: fileUid,
					resourceType,
					resourceAuthorUid: this.formData.resourceAuthorUid
				});
				console.log(this.dragTags)
			},

			//用户编码
			deCodes(str) {
				return this.$util.decode(str);
			},
			//选择作品类型
			checkCardType() {
				console.log(this.formData.resourceType)
				console.log(this.formData, this.transData)
			},
			//选择作品类型
			checkKind() {
				console.log(this.formData.resourceKind)
			},
			// 选中的活动
			filterCampaign(uid) {
				let info = this.campaignList.find(item => item.campaignUid === uid) || {}
				return info
			},
			// 绑定活动
			handleBind(e) {
				const info = this.filterCampaign(e);
				this.formData.resourceName = info.campaignSubject;
				this.formData.resourceDesc = info.campaignContent;
				this.formData.resourceDefaultBlessingText = info.campaignSubject;
			},
			//选择作品种类0
			checkMusic(e) {
				console.log(e)
			},
			checkAuthor(){
				console.log(this.formData.resourceAuthorUid)
			},
			//选择标记
			checkMarker() {
				console.log(this.formData.resourceMarkType)
			},
			//选择字体
			checkFont() {
				console.log(this.formData.fontId)
			},
			// 标签组装
			checkLabels() {
				//需要加ref="tree"
				let arr = [];
				//全选中和半选中状态合并则是选中的所有
				let checkedKeys = this.$refs.tree.getCheckedKeys();
				let hafCheckedKeys = this.$refs.tree.getHalfCheckedKeys();
				arr = checkedKeys.concat(hafCheckedKeys);
				this.checkedLabels = arr;
				console.log(this.checkedLabels)
			},
			//全选树
			checkAllTree() {
				this.$refs.tree.setCheckedNodes(this.labelList)
			},
			cancelAllTree() {
				this.$refs.tree.setCheckedNodes([])
			},

			// 音乐
			checkMusicPage(val) {
				this.$emit('checkMusicPage', val)
			},

			// 选择商品
			checkGoods(e) {
				this.$set(this.formData, 'bindProducts', e);
			},

			// 商品
			checkGoodsPage(val) {
				this.$emit('checkGoodsPage', val)
			},

			// 活动列表分页
			checkCampaignListPage(val) {
				this.$emit('checkCampaignListPage', val)
			},

			updateSubmit(){
				this.$refs['form'].validate((valid) => {
					if (valid) {
						//增加				
						const formData =  {
							resourceUid:this.formData.resourceUid,
							resourceName:this.formData.resourceName,
							resourceDesc:this.formData.resourceDesc,
							resourceCoverImageUrlUid:this.formData.resourceCoverImageUrlUid,
							resourceFileUid:this.formData.resourceFileUid,
							resourceDefaultBlessingText:this.formData.resourceDefaultBlessingText,
							resourceMusicUid:this.formData.resourceMusicUid,
							resourceLabelTreeCodes:this.formData.resourceLabelTreeCodes,
							resourceKind:this.formData.resourceKind,
							resourceAuthorUid:this.formData.resourceAuthorUid,//后端接口名字需要修改
							resourceType:this.formData.resourceType,
							resourceMarkType:this.formData.resourceMarkType,
							resourceSort:this.formData.resourceSort,
							timingRelease:this.formData.timingRelease,
							campaignUid:this.formData.campaignUid,
							videoInfo: this.formData.videoInfo,
							bindProducts: this.bindProducts.toString()
						};

						if (this.formData.resourceType === 5) {
							let dragTagsCopy = [];
							this.dragTags.map(item => {
								const { 
									resourceType, 
									resourceAuthorUid,
									resourceInfo,
									resourceFileUrlUid } = item;
								return dragTagsCopy.push({
									resourceType, 
									resourceInfo,
									resourceAuthorUid,
									resourceFileUrlUid
								})
							});

							// 合集必须包含贺卡和视频
							let requiredParameter = false;
							let arrayTemp = [];
							dragTagsCopy.map(item => {
								if (item.resourceType === 1 || item.resourceType === 4) {
									arrayTemp.push(item.resourceType)
								}
								return item
							});

							//  && arrayTemp.includes(4)
							if (arrayTemp.includes(1)) {
								requiredParameter = true;
							}

							if (!requiredParameter) {
								this.$message({
									message: "合集必需包含贺卡！",
									type: "error"
								});
								return
							}

							// 
							const requiredData = dragTagsCopy.every(item => item.resourceAuthorUid)
							if (!requiredData) {
								this.$message({
									message: "含有未选择作者的作品！",
									type: "error"
								});
								return
							}
							formData.resourceFiles = JSON.stringify(dragTagsCopy);
						}

						this.showLoading = true;
						blessingUpdate(formData).then(res => {
							if (res.data.isSuccessful !== "Y") {
								this.$message.error(res.data.message);
								return
							}
							this.$message({
								message: "修改成功！",
								type: "success"
							});
							setTimeout(() => {
								this.closeDialog(true);
							}, 0);
						}).finally(() => {
							this.showLoading = false;
						});
					}
				})
			},

			closeDialog(refresh){
				this.formData = {};
				this.QiniuData = {};
				this.$emit('func', {
					action: false,
					refresh,
					type: 'edit'
				})
			},

			getdata (evt) {
				console.log(evt.draggedContext.element)
			},
			datadragEnd (evt) {
				console.log('拖动前的索引 :' + evt.oldIndex)
				console.log('拖动后的索引 :' + evt.newIndex)
				console.log(this.dragTags)
			},
		 	 handleSelect(selectAuthData) {
				this.innerVisible = true;
				this.selectAuthData = selectAuthData;
				this.resourceAuthorUid = selectAuthData.resourceAuthorUid
			},
		  	addAuth() {
				this.dragTags.map(item => {
					const {
						resourceFileUrlUid,
						resourceAuthorUid
					} = this.selectAuthData;

					if(item.resourceFileUrlUid === resourceFileUrlUid) {
						item.resourceAuthorUid = resourceAuthorUid
					}
					return item
				});
				
				setTimeout(() => {
					this.cancelAuth()
				}, 300);
				console.log(this.selectAuthData, 'this.selectAuthData')
		  	},
			cancelAuth(state) {
				this.innerVisible = false;
				this.selectAuthData = {}
			},
			innerPopAuthor(e) {
				const memberInfo = this.authorList.find(item => item.memberUid == e);
			},

			// 获取作者名称
			filterAuthName(e) {
				const memberInfo = this.authorList.find(item => item.memberUid == e);
				return	this.deCodes(memberInfo.wechatNickName)
			},
			// 移除
			handleDel(data) {
				this.$confirm("移除操作, 是否继续?", "提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning"
				}).then(() => {
					this.dragTags = this.dragTags.filter(item => item.resourceFileUrlUid !== data.resourceFileUrlUid);
				}).catch(() => {
					this.$message({
						type: "info",
						message: "已取消移除"
					});
				});
			}
      	},
  	}
</script>

